#include <iostream>
#include <fstream>
#include <string>
#include <stdint.h>
#include <stdio.h>
#include "Segmentor.h"
#include "KrwsParameter.h"
#include <dastrie.h>
#include <fstream>
#include <stdlib.h>
#include <Token.h>
#include <Word.h>

using namespace std;


int main(int argc, char *argv[])
{

    std::cout << "input test:";

    string line ="(fdsa)) . ffff    ○ 	△   +/   fsda 13 안녕 ㅋㅋㅋ 잘해봐잘나와야할텐데않나옴 좀웃기겠지?~!.. 정말좋은뭔가나오게..  ㄹㅇㄴ 12";
    line ="비관주의자들은 천체의 비밀을 발견해낸 적도 없고, 미지의 땅을 향해 항해한 적도 없으며, 영혼을 위한 새로운 천국을 열어준 적이 단 한 번도 없습니다.";
    line ="비관주의자들은 abc123 ab";

    if( argc ==2)
        line = argv[1];
    std::cout << line<<":"<< line.length() <<"<--\n";


    //////////////////////////////////////////////////////
    // reading conf file.
    KrwsParameter param( "../conf/krws.conf" );
 //   param.print();
    //////////////////////////////////////////////////////

    /*/////////////////////////////////////////////////////
    // reading word dict for segment
    std::ifstream ifs(  (param.dict_location  + param.word_list_dict).c_str() , std::ios::binary);
    if (ifs.fail()) 
    {
        std::cerr << "ERROR: Failed to open a trie file." << std::endl;
        return 1;
    }
    dastrie::trie<uint16_t> word_dict;
    if (word_dict.read(ifs) == 0) 
    {
        std::cerr << "ERROR: Failed to read a trie file." << std::endl;
        return 1;
    }

    // reading correct dict  for segment
    std::ifstream corr_ifs(  (param.dict_location  + param.seg_correct_dict).c_str() , std::ios::binary);
    if (corr_ifs.fail())
    {
        std::cerr << "ERROR: Failed to open a trie file." << std::endl;
        return 1;
    }
    dastrie::trie<std::string> correct_dict;
    if ( correct_dict.read( corr_ifs ) == 0) 
    {
        std::cerr << "ERROR: Failed to read a trie file." << std::endl;
        return 1;
    }

    /////////////////////////////////////////////////////////////////*/

    
    std::vector<Word> VWords;
    Segmentor seg;
 //   seg.setWordDict( &word_dict );
   // seg.setCorrectDict( &correct_dict );

    seg.setLine ( line );
    seg.segmenting( VWords  );
 
    for( int i =0;i< (int)VWords.size(); i++)
    {
        std::cout << i <<":"<< VWords[i].getString() <<"/"<< (int)VWords[i].type <<"/"<< (int) VWords[i].begin <<"/"<< (int)VWords[i].end <<"\n";
    }

	return 0;
};

